package com.qdlc.p2p.manage.action.additional;

import java.io.IOException;
import java.util.HashMap;
import java.util.Map;

import javax.annotation.Resource;

import org.apache.struts2.convention.annotation.Action;

import com.opensymphony.xwork2.ModelDriven;
import com.qdlc.p2p.biz.service.AdditionalUserMovieTicketService;
import com.qdlc.p2p.biz.web.action.BaseAction;
import com.qdlc.p2p.common.util.StringUtil;
import com.qdlc.p2p.dal.common.model.jpa.PageDataList;
import com.qdlc.p2p.dal.model.AdditionalUserMovieTicketModel;

/**
 * Created by liaoxiangkai on 2015/11/27.
 */
public class ManageUserMovieTicketAction extends BaseAction<AdditionalUserMovieTicketModel> implements ModelDriven<AdditionalUserMovieTicketModel> {
    @Resource
    private AdditionalUserMovieTicketService additionalUserMovieTicketService;

    private AdditionalUserMovieTicketModel model = new AdditionalUserMovieTicketModel();

    public AdditionalUserMovieTicketModel getModel() {
        return model;
    }

    private Map<String, Object> data;

    /**
     * -------------------用户电影票列表---------------------------
     *  进入页面
     * @return
     */
    @Action("/modules/additional/movieTicket/userMovieTicketManager")
    public String userMovieTicketManager() {
        return "userMovieTicketManager";
    }

    @Action("/modules/additional/movieTicket/userMovieTicketList")
    public void userMovieTicketList() throws IOException {
        data = new HashMap<String, Object>();
        String status = paramString("status");
        if (StringUtil.isBlank(status)) model.setStatus(99);

        PageDataList<AdditionalUserMovieTicketModel> pageDataList = additionalUserMovieTicketService.list(model);
        if (pageDataList == null) {
            return;
        }
        data.put("total", pageDataList.getPage().getTotal());
        data.put("rows", pageDataList.getList());
        printJson(getStringOfJpaObj(data));
    }

    /**
     * 手动触发为请求php接口的记录
     */
    @Action("/modules/additional/movieTicket/triggerRequestInterface")
    public void triggerRequestInterface() throws IOException {
        additionalUserMovieTicketService.requestPHPInterface();
        printWebResult("触发成功", true);
    }
}
